<?php
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of ModPadres
 *
 * @author EaDeveloper
 */
class ModAlumnos implements EaSoftModule {

    public $title = "Estudiantes";
    public $maintenance;
    public $relativePath = "modules/students/";
    public $includePath = "students/";
    public $db;
    public $grdEstudents;
    public $grdAsignaturas;
    public $grdCobrosPendientes;
    public $instanceName = "ModAlumnos";
    public $formName = "modestudiantes";
    public $moduleUpload;
    public $widgets;

    public function __construct() {
        $this->widgets = new Widget();
        $this->widgets->rootPath = RELATIVE_PATH . "js_v2/";

        $this->moduleUpload = new ModUploader();
        $this->maintenance = new Maintenance();
        $this->maintenance->table = "cllg_student";
        $this->maintenance->title = 'Mantenimiento Estudiantes';

        $this->maintenance->validations = array("required,ID,Identifiacion es Requerido",
            "required,FIRST_NAME,Nombres es Requerido",
            "required,LAST_NAME,Apellidos es Requerido");

        $this->widgets->register("BIRTH_DATE", 2);

        $this->grdEstudents = new JGridGenerator();
        $this->grdEstudents->table = "cllg_student";
        $this->grdEstudents->fields = array("ID", "FIRST_NAME", "LAST_NAME");
        $this->grdEstudents->colTypes = array("ID" => "int", "FIRST_NAME" => "text", "LAST_NAME" => "text");
        $this->grdEstudents->pk = "ID";
        $this->db = DbManager::getMe();
    }

    public function resetGrids() {
        $this->grdAsignaturas = new JGridGenerator();
        $query = "
            SELECT e.ID,g.CODIGO, g.NOMBRE from cllg_academico_estudiantes_asignacion s,cllg_student e,
                cllg_academico_grados g
                where s.FK_ESTUDIANTE=e.ID and g.ID=s.FK_GRADO";
        $this->grdAsignaturas->whereParams = array("ID" => "ID");
        $this->grdAsignaturas->query = $query;
        $this->grdAsignaturas->search = false;
        $this->grdAsignaturas->fields = array("CODIGO", "NOMBRE");
        $this->grdAsignaturas->pk = "CODIGO";

        $this->grdCobrosPendientes = new JGridGenerator();
        $query = "select c.ID, c.FK_ESTUDIANTE,d.DESCRIPCION,
                c.FECHA,c.VALOR from cllg_academico_cobros c, 
                cllg_academico_cargos_detail d
                    where c.ESTADO='INGRESADO' and c.FK_CARGO_DETAIL_ID=d.ID ";
        $this->grdCobrosPendientes->whereParams = array("ID" => "FK_ESTUDIANTE");
        $this->grdCobrosPendientes->query = $query;
        $this->grdCobrosPendientes->search = false;
        $this->grdCobrosPendientes->fields = array("DESCRIPCION", "FECHA", "VALOR");
        $this->grdCobrosPendientes->pk = "ID";
    }

    public function getCssFiles() {
        $this->maintenance->getCssFiles();
        $this->moduleUpload->getCssFiles();
        ?>
        <link href="<?php echo RELATIVE_PATH; ?>js_v2/fancybox/jquery.fancybox-1.3.4.css"  rel="stylesheet" type="text/css" media="screen" />
        <?php
    }

    public function getJsFiles() {
        $this->maintenance->db = $this->db;
        if ($this->maintenance->builder == null) {
            $this->maintenance->init($this->db);
        }

        $this->maintenance->getJsFiles();
        $this->moduleUpload->getJsFiles();
        ?>
        <script src="<?php echo RELATIVE_PATH; ?>js_v2/fancybox/jquery.mousewheel-3.0.4.pack.js"   type="text/javascript"></script>
        <script src="<?php echo RELATIVE_PATH; ?>js_v2/fancybox/jquery.fancybox-1.3.4.js"   type="text/javascript"></script>
        <script type="text/javascript">
            var AJAX_CORE_URL='<?php echo CORE_PATH ?>?module=<?php echo $this->instanceName; ?>&ajax=true';
        </script>
        <script type="text/javascript" src="<?php echo $this->relativePath; ?>sft.cllg.students.js"  > </script>
        <script type="text/javascript" src="<?php echo $this->relativePath; ?>sft.cllg.datosextra.js"  > </script>
        <script type="text/javascript"  src="<?php echo RELATIVE_PATH; ?>modules/upload/uploads.js"></script>
        <script type="text/javascript" >jQuery.noConflict();</script>
        <script src="<?php echo RELATIVE_PATH; ?>js/prototype.js" type="text/javascript"></script>
        <script src="<?php echo RELATIVE_PATH; ?>js/jsvalidate.js" type="text/javascript"></script>
        <script type="text/javascript">
            var DP_callback=function (){
                setEdad(jQuery("#BIRTH_DATE"),jQuery("#EDAD"));
            }
        <?php
        echo $this->maintenance->loadDynValidations();
        echo $this->maintenance->scriptValidations();
        ?>
        </script>
        <?php
        $this->widgets->db = $this->db;
        $this->widgets->includes();
        $this->widgets->activateWidgets();
    }

    public function getWindowTitle() {
        return $this->title;
    }

    public function main() {
        if (!defined("PATH_UPLOAD_STUDENTS")) {
            define("PATH_UPLOAD_STUDENTS", $this->includePath . DS . $this->relativePath . "upload");
        }
        ModUploader::$PATH_UPLOADS = PATH_UPLOAD_STUDENTS;
        $this->maintenance->db = $this->db;


        $this->resetGrids();
        if (!isEmpty(getParam("operation"))) {
            switch (getParam("operation")) {
                case "students":
                    $this->grdEstudents->db = $this->db;
                    $this->grdEstudents->main();
                    break;
                case "listasig":
                    $this->grdAsignaturas->db = $this->db;
                    $this->grdAsignaturas->main();
                    break;
                case "pendientes":
                    $this->grdCobrosPendientes->db = $this->db;
                    $this->grdCobrosPendientes->main();
                    break;
                case "edit":
                    include $this->includePath . "edit.php";
                    break;
                case "new":
                    include $this->includePath . "new.php";
                    break;
                default: //switch file
                    include $this->includePath . "data.php";
                    include $this->includePath . "main.php";
            }
        } else {
            include $this->includePath . "main.php";
        }
    }

}
?>
